#include "newitemdialog.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QLabel>

NewItemDialog::NewItemDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUI();
}

NewItemDialog::~NewItemDialog() {}

QString NewItemDialog::getType() const { return typeComboBox->currentText(); }
QString NewItemDialog::getId() const { return idEdit->text(); }
QString NewItemDialog::getName() const { return nameEdit->text(); }
QString NewItemDialog::getDescription() const { return descriptionEdit->text(); }

void NewItemDialog::setId(const QString &id) { idEdit->setText(id); }
void NewItemDialog::setName(const QString &name) { nameEdit->setText(name); }
void NewItemDialog::setDescription(const QString &description) { descriptionEdit->setText(description); }

void NewItemDialog::setupUI()
{
    setWindowTitle("新建");

    QVBoxLayout *layout = new QVBoxLayout(this);
    QFormLayout *formLayout = new QFormLayout();

    idEdit = new QLineEdit(this);
    nameEdit = new QLineEdit(this);
    descriptionEdit = new QLineEdit(this);
    typeComboBox = new QComboBox(this);
    typeComboBox->addItems(QStringList() << "产品" << "系统" << "组件" << "零件");

    formLayout->addRow("类型", typeComboBox);
    formLayout->addRow("编号", idEdit);
    formLayout->addRow("名称", nameEdit);
    formLayout->addRow("描述", descriptionEdit);

    layout->addLayout(formLayout);

    okButton = new QPushButton("确定", this);
    cancelButton = new QPushButton("取消", this);

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);
    layout->addLayout(buttonLayout);

    connect(okButton, &QPushButton::clicked, this, &NewItemDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &NewItemDialog::reject);
}